package control;

import dao.Login;
import dao.UserInfo;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import util.WindowMove;


public class LoginController {
    @FXML
    private Button closeButton,minimizeButton;

    @FXML
    private void close(){
        Stage stage = (Stage) closeButton.getScene().getWindow();
        stage.close();
    }
    @FXML
    private void minimize() {
        Stage stage = (Stage) minimizeButton.getScene().getWindow();
        stage.setIconified(true);
    }
    @FXML
    private TextField IdField,PwdField;
    @FXML
    private void login() throws Exception{
        if(Login.userLogin(IdField.getText(),PwdField.getText())){
            System.out.println("登录成功");
            FXMLLoader loader=new FXMLLoader(getClass().getResource("/ui/homePage.fxml"));
            HomePageController homePageController=new HomePageController(UserInfo.getInfo(IdField.getText()));
            loader.setController(homePageController);
            Pane root=loader.load();
            Scene scene=new Scene(root);
            Stage stage = (Stage) closeButton.getScene().getWindow();
            stage.setScene(scene);
            WindowMove.setMoveMode(stage,root);
        }
    }
}
